<?php


abstract class BaseRingtoneComment extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $ringtone_id;


	
	protected $user_id;


	
	protected $content;


	
	protected $created_datetime;


	
	protected $update_datetime;


	
	protected $spam_count;


	
	protected $parent_id;


	
	protected $child_count;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getRingtoneId()
	{

		return $this->ringtone_id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getContent()
	{

		return $this->content;
	}

	
	public function getCreatedDatetime($format = 'Y-m-d H:i:s')
	{

		if ($this->created_datetime === null || $this->created_datetime === '') {
			return null;
		} elseif (!is_int($this->created_datetime)) {
						$ts = strtotime($this->created_datetime);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_datetime] as date/time value: " . var_export($this->created_datetime, true));
			}
		} else {
			$ts = $this->created_datetime;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getUpdateDatetime($format = 'Y-m-d H:i:s')
	{

		if ($this->update_datetime === null || $this->update_datetime === '') {
			return null;
		} elseif (!is_int($this->update_datetime)) {
						$ts = strtotime($this->update_datetime);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [update_datetime] as date/time value: " . var_export($this->update_datetime, true));
			}
		} else {
			$ts = $this->update_datetime;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getSpamCount()
	{

		return $this->spam_count;
	}

	
	public function getParentId()
	{

		return $this->parent_id;
	}

	
	public function getChildCount()
	{

		return $this->child_count;
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = RingtoneCommentPeer::ID;
		}

	} 
	
	public function setRingtoneId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->ringtone_id !== $v) {
			$this->ringtone_id = $v;
			$this->modifiedColumns[] = RingtoneCommentPeer::RINGTONE_ID;
		}

	} 
	
	public function setUserId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = RingtoneCommentPeer::USER_ID;
		}

	} 
	
	public function setContent($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->content !== $v) {
			$this->content = $v;
			$this->modifiedColumns[] = RingtoneCommentPeer::CONTENT;
		}

	} 
	
	public function setCreatedDatetime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_datetime] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_datetime !== $ts) {
			$this->created_datetime = $ts;
			$this->modifiedColumns[] = RingtoneCommentPeer::CREATED_DATETIME;
		}

	} 
	
	public function setUpdateDatetime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [update_datetime] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->update_datetime !== $ts) {
			$this->update_datetime = $ts;
			$this->modifiedColumns[] = RingtoneCommentPeer::UPDATE_DATETIME;
		}

	} 
	
	public function setSpamCount($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->spam_count !== $v) {
			$this->spam_count = $v;
			$this->modifiedColumns[] = RingtoneCommentPeer::SPAM_COUNT;
		}

	} 
	
	public function setParentId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->parent_id !== $v) {
			$this->parent_id = $v;
			$this->modifiedColumns[] = RingtoneCommentPeer::PARENT_ID;
		}

	} 
	
	public function setChildCount($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->child_count !== $v) {
			$this->child_count = $v;
			$this->modifiedColumns[] = RingtoneCommentPeer::CHILD_COUNT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->ringtone_id = $rs->getInt($startcol + 1);

			$this->user_id = $rs->getInt($startcol + 2);

			$this->content = $rs->getString($startcol + 3);

			$this->created_datetime = $rs->getTimestamp($startcol + 4, null);

			$this->update_datetime = $rs->getTimestamp($startcol + 5, null);

			$this->spam_count = $rs->getInt($startcol + 6);

			$this->parent_id = $rs->getInt($startcol + 7);

			$this->child_count = $rs->getInt($startcol + 8);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 9; 
		} catch (Exception $e) {
			throw new PropelException("Error populating RingtoneComment object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RingtoneCommentPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			RingtoneCommentPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RingtoneCommentPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = RingtoneCommentPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += RingtoneCommentPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = RingtoneCommentPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RingtoneCommentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getRingtoneId();
				break;
			case 2:
				return $this->getUserId();
				break;
			case 3:
				return $this->getContent();
				break;
			case 4:
				return $this->getCreatedDatetime();
				break;
			case 5:
				return $this->getUpdateDatetime();
				break;
			case 6:
				return $this->getSpamCount();
				break;
			case 7:
				return $this->getParentId();
				break;
			case 8:
				return $this->getChildCount();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RingtoneCommentPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getRingtoneId(),
			$keys[2] => $this->getUserId(),
			$keys[3] => $this->getContent(),
			$keys[4] => $this->getCreatedDatetime(),
			$keys[5] => $this->getUpdateDatetime(),
			$keys[6] => $this->getSpamCount(),
			$keys[7] => $this->getParentId(),
			$keys[8] => $this->getChildCount(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RingtoneCommentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setRingtoneId($value);
				break;
			case 2:
				$this->setUserId($value);
				break;
			case 3:
				$this->setContent($value);
				break;
			case 4:
				$this->setCreatedDatetime($value);
				break;
			case 5:
				$this->setUpdateDatetime($value);
				break;
			case 6:
				$this->setSpamCount($value);
				break;
			case 7:
				$this->setParentId($value);
				break;
			case 8:
				$this->setChildCount($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RingtoneCommentPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setRingtoneId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setUserId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setContent($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCreatedDatetime($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setUpdateDatetime($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setSpamCount($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setParentId($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setChildCount($arr[$keys[8]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(RingtoneCommentPeer::DATABASE_NAME);

		if ($this->isColumnModified(RingtoneCommentPeer::ID)) $criteria->add(RingtoneCommentPeer::ID, $this->id);
		if ($this->isColumnModified(RingtoneCommentPeer::RINGTONE_ID)) $criteria->add(RingtoneCommentPeer::RINGTONE_ID, $this->ringtone_id);
		if ($this->isColumnModified(RingtoneCommentPeer::USER_ID)) $criteria->add(RingtoneCommentPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(RingtoneCommentPeer::CONTENT)) $criteria->add(RingtoneCommentPeer::CONTENT, $this->content);
		if ($this->isColumnModified(RingtoneCommentPeer::CREATED_DATETIME)) $criteria->add(RingtoneCommentPeer::CREATED_DATETIME, $this->created_datetime);
		if ($this->isColumnModified(RingtoneCommentPeer::UPDATE_DATETIME)) $criteria->add(RingtoneCommentPeer::UPDATE_DATETIME, $this->update_datetime);
		if ($this->isColumnModified(RingtoneCommentPeer::SPAM_COUNT)) $criteria->add(RingtoneCommentPeer::SPAM_COUNT, $this->spam_count);
		if ($this->isColumnModified(RingtoneCommentPeer::PARENT_ID)) $criteria->add(RingtoneCommentPeer::PARENT_ID, $this->parent_id);
		if ($this->isColumnModified(RingtoneCommentPeer::CHILD_COUNT)) $criteria->add(RingtoneCommentPeer::CHILD_COUNT, $this->child_count);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(RingtoneCommentPeer::DATABASE_NAME);

		$criteria->add(RingtoneCommentPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setRingtoneId($this->ringtone_id);

		$copyObj->setUserId($this->user_id);

		$copyObj->setContent($this->content);

		$copyObj->setCreatedDatetime($this->created_datetime);

		$copyObj->setUpdateDatetime($this->update_datetime);

		$copyObj->setSpamCount($this->spam_count);

		$copyObj->setParentId($this->parent_id);

		$copyObj->setChildCount($this->child_count);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new RingtoneCommentPeer();
		}
		return self::$peer;
	}

} 